﻿using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Gre_Wp7
{
    

    public class Word
    {
        static List<CWord> _list;
        public int Page = 0;
        public int PageNumber = 5;


        public Word()
        {
            if (_list == null)
            {
                _list = new List<CWord>();

                System.IO.Stream testpath = Application.GetResourceStream(new Uri(@"Word/1.txt", UriKind.Relative)).Stream;
                System.IO.StreamReader reader = new System.IO.StreamReader(testpath, System.Text.Encoding.UTF8);

                string cstring = reader.ReadLine();
                while (cstring != null)
                {
                    CWord cw = new CWord();
                    cw.English = cstring.Substring(0, 24);
                    cw.Meaning = cstring.Substring(24);
                    _list.Add(cw);


                    cstring = reader.ReadLine();
                }

                reader.Close();
                testpath.Close();
            }
        }

        public CWord[] AddPageArray()
        {
            Page++;

            Page = Page % (_list.Count / PageNumber);
            return GetPageArray(Page);
        }

        public CWord[] SubPageArray()
        {
            Page--;

            Page = (Page + _list.Count / PageNumber) % (_list.Count / PageNumber);
            return GetPageArray(Page);
        }
        public int CurPage
        {
            get { return Page; }
        }

        public CWord[] GetPageArray(int page)
        {
            if (_list == null)
                return null;

            if (page * PageNumber >= _list.Count)
                return null;



            if (page * PageNumber >= _list.Count)
                return null;

            CWord[] cw = new CWord[PageNumber];
            for (int i = 0; i < PageNumber; i++)
            {
                if (page * PageNumber + i < _list.Count)
                    cw[i] = _list[page * PageNumber + i];
            }
            return cw;
        }
    }



    public class CWord
    {
        public int Id;
        public string English;
        public string Meaning;
    }
}
